//
//  WorkServicesSubViewController.m
//  ASHT_IOS
//
//  Created by Hui Li on 14-4-10.
//  Copyright (c) 2014年 宋安安. All rights reserved.
//

#import "WorkServicesSubViewController.h"
#import "WorkServicesCell.h"
#import "WorkServiceEntity.h"
#import "NewsInfoEntity.h"
#import "AFAppDotNetAPIClient.h"

@interface WorkServicesSubViewController ()

@end

@implementation WorkServicesSubViewController

@synthesize headName;
@synthesize imgUrl;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _Adaptation=YES;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.subTableView.dataSource = self;
    self.subTableView.delegate = self;
    self.headLabel.text = headName;
    [self imageUrl:imgUrl];
    
    // Do any additional setup after loading the view from its nib.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    {
        if (_Adaptation) {
            self.view_Content.frame=CGRectMake(self.view_Content.frame.origin.x,self.view_Content.frame.origin.y,self.view_Content.frame.size.width,self.view_Content.frame.size.height-20);
            _Adaptation=NO;
        }
        
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    //去掉分割线
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;

    return self.subArray.count;
}

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    static NSString *CellIdentifier = @"WorkServicesIdentifier";
    
    WorkServicesSubCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
	if (cell == nil) {
        NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"WorkServicesCell" owner:self options:nil];
        cell = [nibViews objectAtIndex:1];
        nibViews=nil;
        
	}
    WorkServiceEntity *entity = [self.subArray objectAtIndex:row];
    cell.lab_cellname.text = entity.categoryName;
    
    return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int newIndex = [indexPath row];
    int lastIndex = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    if (newIndex != lastIndex) {
        WorkServicesSubCell *cell= (WorkServicesSubCell*)[tableView cellForRowAtIndexPath:indexPath];
        CGRect rect = cell.lab_cellname.frame;
        rect.origin.x = cell.lab_cellname.frame.origin.x + 10;
        cell.lab_cellname.frame  = rect;
        
        cell= (WorkServicesSubCell*)[tableView cellForRowAtIndexPath:lastIndexPath];
        CGRect rect1 = cell.lab_cellname.frame;
        rect1.origin.x = cell.lab_cellname.frame.origin.x - 10;
        cell.lab_cellname.frame  = rect1;
        lastIndexPath = indexPath;
    }
    int row = [indexPath row];
    WorkServiceEntity *serviceEntity = [self.subArray objectAtIndex:row];

    thirdView = [[WorkServicesThirdViewController alloc] initWithNibName:XIB_Version(@"WorkServicesThirdViewController") bundle:nil];
    thirdView.categoryId = serviceEntity.categoryId;
    thirdView.headName = serviceEntity.categoryName;
    [self.app.viewDeckController.navigationController pushViewController:thirdView animated:YES];
    
    
    
    
}

-(void)imageUrl:(NSString *)url
{
    NSString *str_url=[NSString stringWithFormat:SERVER_BASICE_URL@"phone!getImg.action?imgUrl=%@",url];
    NSURL *imageurl=[[NSURL alloc] initWithString:str_url];
    [self.headEgoImage setImageURL:imageurl];
}




@end
